<?php 
include_once('connection/connection.php');
include('config.php');
//session_start();
//ob_start();
include('header.php');
include('menu.php');
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="css/style_question.css" type="text/css" rel="stylesheet"/>
<style type="text/css" media="screen">
			
			.suggest_link {
				background-color: #FFFFFF;
				padding: 5px 16px 5px 16px;
			}
			.suggest_link_over {
				background-color: #3366CC;
				padding: 5px 16px 5px 16px;
			}
			.search_suggest {
				position: absolute; 
				background-color: #FFFFFF; 
				text-align: left; 
				border: 1px solid #000000;
				font-family:Verdana, Arial, Helvetica, sans-serif;
				color:#000000;
				font-size:9px;			
			}
				
		</style>
<script language="Javascript" type="text/javascript" src="js/ajaxFunction1_q1.js"></script>
<script language="Javascript" type="text/javascript" src="js/ajaxFunction_ufw.js"></script>
<script language="Javascript" type="text/javascript" src="js/ajax_search.js"></script>
<script language="Javascript" type="text/javascript" src="js/validate.js"></script>
<script language=javascript>
/*function mult2()
{
	var value1=document.getElementById('factor1').value;
	var value4=document.getElementById('factor2').value;
	var value2=document.getElementById('population_benefited1').value;
	var value3=Math.round(value1 * value2);
	var value5=Math.round(value4 * value2);
	document.getElementById('present_population1').value=value3;
	document.getElementById('future_population1').value=value5;
	alert('Value of Population Benefited Field is '+ value2 +', Present Population is '+ value3 +', population of 2025 is '+value5+' and Population Factor is ' + value1 +' and '+value4);	
}*/
</script>
<title>UFW Form</title>
</head>
<body>
<?php
date_default_timezone_set('Asia/Kolkata');
$stamp = time();
$getdate = getdate($stamp);
	////////////////////////////////////////// function for dob starts //////////////
function dpulldown($name,$d,$m,$y)//This function will provide the pulldown for date
{
	$stamp = time();
	$getdate = getdate($stamp);
	$months = array(1 => 'January','February','March','April','May','June','July','August','September','October','November','December');
	echo'<select name="'.$name.'date" class="date">';
	for($date = 1; $date <= 31; $date++)
	{
		echo'<option value="'.$date.'" ';if($d == $date) echo'selected="selected"'; echo'>'.$date.'</option>';
	}
	echo'</select>';
	echo'<select name="'.$name.'month" class="date">';
	foreach($months as $key => $value)
	{
		echo'<option value="'.$key.'" ';if($m == $key) echo'selected="selected"'; echo'>'.$value.'</option>';
	}
	echo'</select>';
	echo'<select name="'.$name.'year" class="date">';
	for($year = 2005; $year <= ($getdate['year']); $year++)
	{
		echo'<option value="'.$year.'" ';if($y == $year) echo'selected="selected"'; echo'>'.$year.'</option>';
	}
	echo'</select>';
}
 
if(isset($_POST['submit']))
{ 
		$fclick = true;
		$id=$_POST['id'];
		$_SESSION['id']=$id;
		$form_id=$_POST['form_id'];
		$_SESSION['form_id']=$form_id;
		$rwss_name=$_POST['rwss_name'];
		$dob = $_POST['dobyear'].'-'.$_POST['dobmonth'].'-'.$_POST['dobdate'];
		$team_leader=$_POST['team_leader'];
		$num_src_village=$_POST['num_src_village'];
		/*$habit1=$_POST['habit1'];*/
		echo $_SESSION['num_src_village']=$num_src_village;
		$total_quant=$_POST['total_quant'];
		$year=$_POST['year'];
		$investment=$_POST['investment'];
		$district=$_POST['muldist'];
		$block=$_POST['mulblock'];
		$panchayat=$_POST['mulpanchayat'];
		$village=$_POST['mulvillage'];
		$cvc=$_POST['cvc'];
		/*$popul_benefited=$_POST['population_benefited1'];
		$present_popul=$_POST['present_population1'];
		$future_popul=$_POST['future_population1'];*/
		
		$q1="INSERT INTO tbl_dtls_ufw_main(id, form_id, name_rwss, date, team_leader, num_source, year_com, capital,  multi_dist_id, multi_block_id, multi_panchayat_id, multi_village_id, cvc, water_source, post_date) VALUES('$id', '$form_id', '$rwss_name', '$dob', '$team_leader', '$num_src_village', '$year', '$investment', '$district', '$block', '$panchayat', '$village', '$cvc', '$total_quant', NOW())";
			//echo $q1;
			$r1=mysql_query($q1);
			if($r1)
			{
				//echo "success 1";	
				$relocatePage=true;	
			}
			else 
			{
				$errorIns="Error inserting ufw_main table <br>";
			}
			/*-------------------------------------------------*/
			$q2="SELECT id FROM tbl_dtls_ufw_main where form_id='$form_id'";
			$r2=mysql_query($q2);
			$x=mysql_fetch_array($r2);
			$loc_id=$x['id'];
			$_SESSION['loc_id']=$loc_id;
			
			if($_POST['num_src_village']!=0 || $_POST['num_src_village']!='')
			{
				if($num_src_village >0) 
				{
					for($i=1; $i<=$num_src_village; $i++)
					{
						$district_name='district_name'.$i;
						$block_name='block_name'.$i;
						$panchayat_name='panchayat_name'.$i;
						$village_name='village_name'.$i;
						$district_name=$_POST[$district_name];
						$_SESSION['district_name']=$district_name;
						$block_name=$_POST[$block_name];
						$panchayat_name=$_POST[$panchayat_name];
						$village_name=$_POST[$village_name];
						/*$source_village[i]=$village
						$_SESSION['src_village']=$source_village;*/
						//echo "<br>";
						$qr2="INSERT INTO tbl_dtls_ufw_src_village(loc_id, district, block, panchayat, village) VALUES ('$loc_id', '$district_name', '$block_name', '$panchayat_name', '$village_name')";
						//echo $qr2;
						$result2=mysql_query($qr2);
					}
				}
						if($result2)
						{
							//echo "success 1";	
							$relocatePage=true;	
						}
						else 
						{
							$errorIns="Error inserting ufw_src_village table <br>";
						}
			}
			$q3="SELECT DISTINCT habitation_code, habitation_name from tbl_lookup_location where village_id IN($village)";
			$r3=mysql_query($q3);
			$num_rows = mysql_num_rows($r3);
			//$_SESSION['num_rows']=$num_rows;
			//echo $num_rows;
			for($i=1; $i<=$num_rows; $i++)
			{
				$hname = 'name_habi'.$i;
				$hcode = 'habi_code'.$i;
				$type_habit='type_habit'.$i;
				$status_a_na = 'status_a_na'.$i;
				$popul_benefited = 'population_benefited'.$i;
				$present_popul = 'present_population'.$i;
				$future_popul = 'future_population'.$i;
				$quant_boundary = 'quant_boundary'.$i;
				//$per_capita = 'per_capita'.$i;
				
				$hname=$_POST[$hname];	
				$hcode=$_POST[$hcode];
				$type_habit=$_POST[$type_habit];
				$status_a_na=$_POST[$status_a_na];
				$popul_benefited=$_POST[$popul_benefited];
				$present_popul=$_POST[$present_popul];
				$future_popul=$_POST[$future_popul];
				$quant_boundary=$_POST[$quant_boundary];
				//$per_capita=$_POST[$per_capita];
				//echo "<br>";
				$q4="INSERT INTO tbl_dtls_ufw_habit(loc_id, habit_name, habit_code, type_habit, status_a_na, pop_2001, pop_2010, pop_2025, water_boundary) VALUES ('$loc_id', '$hname', '$hcode', '$type_habit', '$status_a_na', '$popul_benefited', '$present_popul', '$future_popul', '$quant_boundary')";
				$r4=mysql_query($q4);	
			}	
			if($r4)
			{
				$relocatePage=true;
			}
			else 
			{
				$errorIns.="Error inserting habit table <br>";
			}
			
			$num_unhabit=$_POST['num_unhabit'];
			for($i=1; $i<=$num_unhabit; $i++)
			{
				$un_habit_ufw='un_habit_ufw'.$i;
				$un_habit_ufw=$_POST[$un_habit_ufw];
				$q5="INSERT INTO tbl_dtls_ufw_unhabit(loc_id, unhabit_name) VALUES ('$loc_id', '$un_habit_ufw')";
				$r5=mysql_query($q5);	
			}	
			if($r5)
			{
				//$relocatePage=true;
				//echo "success 2";
				$relocatePage=true;
			}
			else 
			{
				$errorIns.="Error inserting un_habit table <br>";
			}
			if($errorIns==0) 
			{
				header('Location: ufw_2.php');
			}
			else 
			{ 
				echo $errorIns;exit;
			}
}
else
{
	$fclick = false;
	$flag=0;
}
?>
<div align="center">
<!--<form action="" method="post" enctype="multipart/form-data" name="ufw" id="ufw" onSubmit="return mult2();">-->
<form action="" method="post" enctype="multipart/form-data" name="ufw" id="ufw" onSubmit="return ufw1()">
	<table border="0" width="800" id="table1" cellspacing="0" cellpadding="0">
		<tr>
			<td height="30" colspan="2">
			<p align="center"><span style="font-weight: 700">
			<font face="Verdana" size="2" color="#000000">UFW</font></span></p></td>
		</tr>
		<tr>
			<td height="18" colspan="3" align="center"><font face="Arial" style="font-size: 8.5pt" color="#000000">Page 1</font></td>
		</tr>
		<tr>
			<td height="19" colspan="2" align="center"><font face="Arial" style="font-size: 8.5pt" color="#000000">(This Web Application is More Compatible with Mozilla Firefox and Google Chrome)</font></td>
		</tr>
		
		<tr>
			<td height="27" colspan="2" bgcolor="#C5D8EB"><span style="font-weight: 800">
			<font face="Arial" size="2" style="font-size: 8.5pt" color="#000000">&nbsp;RWSS
			Details</font></span></td>
		</tr>
		
		<tr>
			<td colspan="2" bgcolor="#FDF9EE">
			<div align="left">
			<table border="0" width="800" id="table6" bgcolor="#FDF9EE" cellspacing="1" cellpadding="0">
				<tr>
					<td colspan="4">
					<span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="251" height="23" valign="top">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Name of RWSS</font></td>
				  <td width="170" valign="top"><input type="text" name="rwss_name" id="rwss_name" size="20" class="txt"></td>
				  <td width="120" valign="top"><p align=""><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Date of Survey</font></td>
				  <td width="254" valign="top"><?php dpulldown('dob',$getdate['mday'],$getdate['mon'],$getdate['year']);?></td>
				</tr>
				<tr>
					<td valign="top" colspan="4">&nbsp;</td>
				</tr>
				<tr>
					<td width="251" height="22" valign="top">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Name of Survey Team Leader </font></td>
				  <td width="170" valign="top"><input type="text" name="team_leader" id="team_leader" size="20" class="txt"></td>
					<!--<td width="154" valign="top"><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Name of Survey &nbsp;Team</font></td>
				  <td width="233" valign="top"><select size="1" name="steam" id="steam" class="txt" >
						<option selected value="0">Select Survey Team</option>
						<?php 
						/*foreach($survey_team as $key=>$val)
						{
		   					echo "<option value=\"$val\">$val</option>";
						}*/
						?>
				  </select></td>-->
				</tr>
				<tr>
					<td valign="top" colspan="4">&nbsp;</td>
				</tr>
				<tr>
					<td bgcolor="#C5D8EB" height="28" colspan="4"><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">&nbsp;RWSS  Source Village</font></span></td>
				</tr>
				<tr>
					<td colspan="4">
					<span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="251" height="23" valign="top" bgcolor="#FDF9EE">
					<font style="font-size: 8.5pt" face="Verdana" color="#000000">&nbsp;No. of Source Villages</font></td>
					<td valign="top" bgcolor="#FDF9EE" colspan="3"><input type="text" name="num_src_village" id="num_src_village" size="20" class="txt5" onKeyUp="numeric(this);show_src_village()"></td>
				</tr>
				<tr><td colspan="4"><span style="font-size: 4pt">&nbsp;</span></td></tr>
			   <tr><td colspan="4"><div id="src_village"></div></td></tr>
				<tr><td colspan="4"><span style="font-size: 4pt">&nbsp;</span></td></tr>
				<tr>
					<td width="251" height="24"><font style="font-size: 8.5pt" face="Verdana" color="#000000">&nbsp;Total quantity of water produced at &nbsp;source (KLD)</font></td>
				  <td colspan="3"><input type="text" name="total_quant" id="total_quant" size="20" class="txt" onBlur="float2dec(this)"></td>
				</tr>
				<tr>
					<td valign="top" bgcolor="#FDF9EE" colspan="4">&nbsp;</td>
				</tr>
				<tr>
					<td width="251"><font style="font-size: 8.5pt" face="Verdana" color="#000000">&nbsp;Year of Commissioning </font></td>
				  <td width="170" valign="top" colspan="3"><select size="1" name="year" id="year" class="txt">
						<option selected value="0">Not Provided</option>
						<?php 
						foreach($year_comm as $key=>$val)
						{
		   					echo "<option value=$val>$val</option>";
						}
						?>
				  </select></td>
				</tr>
				<tr>
					<td valign="top" bgcolor="#FDF9EE" colspan="4">&nbsp;</td>
				</tr>
				<tr>
					<td width="251"><font style="font-size: 8.5pt" face="Verdana" color="#000000">&nbsp;Initial Investment &nbsp;&nbsp;(<img src="images/26rup1.jpg" width="10"> in Lacs)</font></td>
					<td width="170" valign="top" colspan="3"><input type="text" name="investment" id="investment" size="20" class="txt"></td>
				</tr>
				<tr>
					<td valign="top" colspan="4">&nbsp;</td>
				</tr>
				<tr>
					<td height="24" colspan="4" valign="center" bgcolor="#C5D8EB"><font face="Arial" color="#000000"><span style="font-size: 8.5pt; font-weight: 700">&nbsp;RWSS Location</span></font></td>
				</tr>
				<tr>
					<td valign="top" colspan="4">&nbsp;</td>
				</tr>
				<tr>
					<td width="251" valign="center"><font style="font-size: 8.5pt" face="Verdana" color="#000000">&nbsp;Districts</font></td>
					<td class="txt" valign="center" colspan="3">
					  <font id="district2">
					    <select name="district2" id="district2" class="txt">
                          <option value="0">Select District</option>
                        </select>
					  </font><span id="districtLoader2"></span>
					    <font id="factor">
					    <input type="hidden" class="txt5" size="20">
					    <input type="hidden" class="txt5" size="20">
					    </font>
					    <input type="button" name="del" value="<<" onClick="return removeOption('block2',document.getElementById('multiDist'))"/>
						  <select name="multiDist" size="4" multiple="multiple" id="multiDist" style="font-family:Verdana; font-size:8pt" >
			      </select></td>
			  </tr>
				  <tr>
					<td width="251" valign="center"><font style="font-size: 8.5pt" face="Verdana" color="#000000">&nbsp;Blocks</font></td>
					<td valign="center" colspan="3">
					<font id="block2">
							<select name="block2" id="block2" class="txt">
								<option value="0">==============</option>
					  </select></font><span id="blockLoader2"></span>
							<input type="button" name="del2" value="<<" onClick="return removeOption('panchayat2',document.getElementById('multiBlock'))" />
							<select name="multiBlock" size="4" multiple="multiple" id="multiBlock" style="font-family:Verdana; font-size:8pt"  >
                  </select></td>
				</tr>
				<tr>
					<td width="251" valign="center">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Grampanchayats</font></td>
					<td valign="center" class="txt" colspan="3">
					<font id="panchayat2">
						<select name="panchayat2" id="panchayat2" class="txt">
						<option value="0">==============</option>
					  </select></font><span id="panchayatLoader2"></span>
					<input type="button" name="del222" value="<<" onClick="return removeOption('village2',document.getElementById('multiPanchayat'))">
			            <select name="multiPanchayat" size="4" multiple="multiple" id="multiPanchayat" style="font-family:Verdana; font-size:8pt">
                  </select></td>
			  </tr>
				  <tr>
					<td width="251" valign="center"><font style="font-size: 8.5pt" face="Verdana" color="#000000">&nbsp;Villages Covered (MH) with Census &nbsp;Code</font></td>
					<td valign="top" class="txt" colspan="3">
					<font id="village2">
						<select name="village2" id="village2" class="txt">
						<option value="0">==============</option>
					  </select></font><span id="villageLoader2"></span>
				       <input type="button" name="del223" value="<<" onClick="return removeOption('habit',document.getElementById('multiVillage'))"/>
				        <select name="multiVillage" size="4" multiple="multiple" id="multiVillage" style="font-family:Verdana; font-size:8pt" >
                  </select></td>
				</tr>
				<tr>
					<td width="251" height="19">&nbsp;</td>
					<td colspan="3"><div id=cvc style="display:none">
						<input type="text" size="23" class="txt" value="">	
				  </div></td>
				</tr>
				<tr>
					<td width="251" height="24">&nbsp;
						<font style="font-size: 8.5pt" face="Verdana" color="#000000"><font color="#FF0000">*</font>Form Id</font></td>
					<td colspan="3"><div id="form_id">
						<input type="text" size="23" class="txt" value="" readonly><font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;&nbsp;Keep this form Id for further reference</font></div>				  </td>
				</tr>
				</table>
			</div>			</td>
		</tr>
		<tr>
			<td height="27" colspan="10" bgcolor="#C5D8EB">
			<font style="font-size: 8.5pt; font-weight: 700" face="Arial" color="#000000">&nbsp;Habitations covered</font></td>
		</tr>
		
		<tr>
			<td colspan="2">
			<table border="0" width="800" id="table3" bgcolor="#FDF9EE" cellspacing="1" cellpadding="0">
				<tr>
					<td colspan="9"><span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td align="center" width="23%" bgcolor="#F7E6B7" height="28">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">Name of Habitations</font></td>
					<td align="center" width="11%" bgcolor="#F7E6B7" height="28">
						<font style="font-size: 8.5pt" face="Verdana" color="#990000">
						Code No. (As per IMIS)</font></td>
						<td align="center" width="6%" rowspan="" bgcolor="#F7E6B7">
						<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Type MH/ OH</font></td>
					<td align="center" width="11%" bgcolor="#F7E6B7" height="28">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">
						Actual Status at Site (A/NA)</font></td>
						<td align="center" width="12%" bgcolor="#F7E6B7" height="28">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">
						Population as per 2001</font></td>
						<td align="center" width="10%" bgcolor="#F7E6B7" height="28">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">
						Current population 2010</font></td>
						<td align="center" width="14%" bgcolor="#F7E6B7" height="28">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">
						Projected population 2025</font></td>
				    <td align="center" width="13%" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Quantity of water received at village boundary &nbsp;(KLD)</font></td>
				    <!--<td align="center" width="10%" bgcolor="#F7E6B7"><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Per Capita Delivery (lpcd)</font></td>-->
				</tr>	
			  </table></td></tr>
	<tr><td colspan="2"><div id="habit"></div></td></tr>
	<tr><td colspan="5"><span style="font-size: 4pt">&nbsp;</span></td></tr>
	<tr><td colspan="10">&nbsp;</td></tr>
		<tr>
			<td width="173" height="28" bgcolor="#C5D8EB">&nbsp;
			<font style="font-size: 8.5pt; font-weight: 700" face="Arial" color="#000000">No. of Unlisted Habitation</font></td>
		    <td width="627" bgcolor="#EEEEEE"><input type="text" name="num_unhabit" id="num_unhabit" value="" class="txt5" onKeyUp="showunhabit();numeric(this)"></td>
		</tr>
		<tr><td colspan="3">&nbsp;</td></tr>
		
		
		<tr><td colspan="5">&nbsp;</td></tr>
		<tr>
		<td colspan="5"><p align="center">
			<input type="submit" value="Click for Continue" name="submit">&nbsp;</p></td>
	</tr>
	<tr>
		<td colspan="3">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="3">&nbsp;</td>
	</tr>
		</table>
</form>
</div>
</body>
</html>